<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>励控智能终端</title>
    <link rel="stylesheet" href="lib/layui/css/layui.css"/>
    <style>
        .layui-anim {
            -webkit-animation-fill-mode: none;
            animation-fill-mode: none;
        }

        .layui-table-cell {
            height: auto !important;
        }


        .old-version{
           display:none;
        }

        .new-version{
           display:none;
        }

    </style>
</head>

<body>
<div>
    <div class="layui-row">
        <div class="layui-col-sm8 layui-col-sm-offset2">
            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">网络设置</li>
                    <li>服务器设置</li>
                    <li>课室绑定</li>
                    <li>串口设置</li>
                    <li>自定义开关控制码</li>
                    <li>PC控制</li>
                    <li>设备信息</li>
                    <li>用户账号</li>
                    <li>平台对接</li>
                    <li>终端升级</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <form class="layui-form" action="" lay-filter="network">
                            <div class="layui-form-item">
                                <label class="layui-form-label">IP地址</label>
                                <div class="layui-input-block">
                                    <input type="text" name="locip" required
                                           lay-verify="required|ip"
                                           placeholder="请输入本机IP"
                                           autocomplete="off" class="layui-input" id="locip">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">网关地址</label>
                                <div class="layui-input-block">
                                    <input type="text" name="locgetway" required
                                           lay-verify="required|ip"
                                           placeholder="请输入网关地址" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">子网掩码</label>
                                <div class="layui-input-block">
                                    <select name="locmask" required lay-verify="required"
                                            placeholder="请输入子网掩码地址">
                                        <option value="255.255.255.0">255.255.255.0</option>
                                        <option value="255.255.0.0">255.255.0.0</option>
                                        <option value="255.0.0.0">255.0.0.0</option>
                                        <option value="255.255.255.254">255.255.255.254</option>
                                        <option value="255.255.255.192">255.255.255.192</option>
                                        <option value="255.255.255.224">255.255.255.224</option>
                                        <option value="255.255.255.240">255.255.255.240</option>
                                        <option value="255.255.255.248">255.255.255.248</option>
                                        <option value="255.255.255.252">255.255.255.252</option>
                                        <option value="255.255.240.0">255.255.240.0</option>
                                        <option value="255.255.248.0">255.255.248.0</option>
                                        <option value="255.255.252.0">255.255.252.0</option>
                                        <option value="255.255.254.0">255.255.254.0</option>
                                        <option value="255.255.255.128">255.255.255.128</option>
                                        <option value="255.255.128.0">255.255.128.0</option>
                                        <option value="255.255.192.0">255.255.192.0</option>
                                        <option value="255.255.224.0">255.255.224.0</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">DNS地址</label>
                                <div class="layui-input-block">
                                    <input type="text" name="locdns" required
                                           lay-verify="required|ip"
                                           placeholder="请输入DNS服务器地址" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="networkset">
                                        立即提交
                                    </button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <form class="layui-form" action="" lay-filter="server">
                            <div class="layui-form-item">
                                <label class="layui-form-label">服务器IP</label>
                                <div class="layui-input-block">
                                    <input type="text" name="serverip" required
                                           lay-verify="required|ip"
                                           placeholder="请输入WEB服务器IP" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">服务器端口</label>
                                <div class="layui-input-block">
                                    <input type="text" name="serverport" required
                                           lay-verify="required|number"
                                           placeholder="请输入WEB服务器端口" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="serverset">
                                        立即提交
                                    </button>

                                    <button type="reset" class="layui-btn layui-btn-primary">重置
                                    </button>
                                    <button class="layui-btn  layui-btn-primary" lay-submit
                                            lay-filter="servertest">
                                        测试连接
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <form class="layui-form" action="" lay-filter="room" id="room">
                            <div class="layui-form-item">
                                <label class="layui-form-label">绑定教室</label>
                                <div class="layui-input-block">
                                    <input type="text" id="pidSelect" lay-filter="pidSelect"
                                           name="pidSelect"
                                           placeholder="选择需要绑定的教室" lay-verify="required|number"
                                           class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="roombind">
                                        立即提交
                                    </button>

                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <form class="layui-form" action="" lay-filter="serialport" id="serialport">
                            <div class="old-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">USB1</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB1">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate1">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="old-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">USB2</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB2">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate2">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="old-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">USB3</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB3">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate3">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="old-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">USB4</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB4">
                                            <option value="">无</option>
                                            F
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate4">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="old-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">USB5</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB5">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate5">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="old-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">USB6</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB6">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate6">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="old-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">USB7</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB7">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate7">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="new-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">RS485-1</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB1">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate1">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="new-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">RS485-2</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB2">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate2">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="new-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">RS485-3</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB3">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate3">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="new-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">RS485-4</label>
                                    <div class="layui-input-block">
                                        <select name="ttyS5">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="ttySBaudRate5">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="new-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">RS232-4</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB5">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate5">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="new-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">RS232-3</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB6">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate6">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="new-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">RS232-2</label>
                                    <div class="layui-input-block">
                                        <select name="ttyS4">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="ttySBaudRate4">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="new-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">RS232-1</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB8">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate8">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="new-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">IR</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB9">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate9">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="new-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">USB-1-2</label>
                                    <div class="layui-input-block">
                                        <select name="serialUSB10">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="attendancereader">考勤刷卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="serialBaudRate10">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="new-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">ttyS0</label>
                                    <div class="layui-input-block">
                                        <select name="ttyS0">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="ttySBaudRate0">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="new-version">
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">ttyS2</label>
                                    <div class="layui-input-block">
                                        <select name="ttyS2">
                                            <option value="">无</option>
                                            <option value="controller">中控</option>
                                            <option value="cardreader">读卡器</option>
                                            <option value="computer">电脑通讯</option>
                                            <option value="airctrl">空调控制器</option>
                                            <option value="airpower">智能空开</option>
                                            <option value="controlpanel">控制面板</option>
                                            <option value="hdmimatrix">HDMI矩阵</option>
                                            <option value="infraredbus">红外转发</option>
                                            <option value="envsensor">环境传感器</option>
                                            <option value="recordinghost">录播主机</option>
                                            <option value="pctablet">交互大屏</option>
                                            <option value="switcher">继电器</option>
                                            <option value="outermatrix">外接矩阵</option>
                                            <option value="amplifier">功放</option>
                                            <option value="other1">自定义1</option>
                                            <option value="other2">自定义2</option>
                                            <option value="other3">自定义3</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="flex:1;">
                                    <label class="layui-form-label">波特率</label>
                                    <div class="layui-input-block">
                                        <select name="ttySBaudRate2">
                                            <option value="9600">9600</option>
                                            <option value="2400">2400</option>
                                            <option value="4800">4800</option>
                                            <option value="14400">14400</option>
                                            <option value="19200">19200</option>
                                            <option value="38400">38400</option>
                                            <option value="56000">56000</option>
                                            <option value="57600">57600</option>
                                            <option value="115200">115200</option>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="serialport">
                                        保存
                                    </button>

                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <form class="layui-form" action="" lay-filter="customSysCode">
                            <div class="layui-form-item">
                                <label class="layui-form-label">开系统码</label>
                                <div class="layui-input-block">
                                    <input type="text" name="openCode" lay-verify="c"
                                           placeholder=""
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">关系统码</label>
                                <div class="layui-input-block">
                                    <input type="text" name="closeCode" lay-verify="closeCode"
                                           placeholder=""
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="customSysCode">保存
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <form class="layui-form" action="" lay-filter="pcCtrl">
                            <div class="layui-form-item">
                                <label class="layui-form-label">MAC地址</label>
                                <div class="layui-input-block">
                                    <input type="text" name="mac" lay-verify="mac"
                                           placeholder="请输入电脑MAC地址,留空则不进行魔术包控制" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="pcCtrl">保存
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <form class="layui-form" action="" lay-filter="deviceType">
                            <div class="layui-form-item">
                                <label class="layui-form-label">设备类型</label>
                                <div class="layui-input-inline">
                                    <select name="deviceType" lay-verify="required">
                                        <option value="new_ctrl">智能终端BMT3000系列</option>
                                        <option value="old_ctrl">网络中控BMT2000系列</option>
                                        <option value="getway_LK">中控网关</option>
                                        <option value="getway-media-LK">励控多媒体网关</option>
                                    </select>
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    <a style="margin-left: 20px;color:blue;cursor: pointer;"
                                       onclick="adminAuth('deviceType')">保存</a>
                                </div>
                            </div>
                        </form>
                        <div style="padding-left: 40px;margin-top: 60px;"><span>自定义设备协议</span>
                            <a
                                    style="margin-left: 20px;color:blue;cursor: pointer;"
                                    onclick="adminAuth('protocol')">加载列表</a>
                            <a
                                    style="margin-left: 20px;color:blue;cursor: pointer;"
                                    onclick="adminAuth('addprotocol')">添加协议</a>
                            <a
                                    style="margin-left: 20px;color:blue;cursor: pointer;"
                                    onclick="adminAuth('exportprotocol')">导出协议</a>
                            <a
                                    style="margin-left: 20px;color:blue;cursor: pointer;"
                                    onclick="adminAuth('importprotocol')">导入协议</a>
                        </div>
                        <div style="padding: 8px 40px;color: red;display: none;" id="restartTap">
                            <span>设备控制协议发生变化，重启后生效</span> <a
                                style="margin-left: 20px;color:darkorange;cursor: pointer;"
                                onclick="rebootSys()">立即重启</a></div>
                        <div style="margin-top: 8px;padding: 0 40px;">
                            <table id="protocolTable" lay-filter="protocolTable"></table>
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <table class="layui-table" lay-skin="row" id="user" lay-filter="user">

                        </table>

                    </div>
                    <div class="layui-tab-item">
                        <div style="padding: 16px 42px;border: 1px solid #999;margin-bottom: 20px;border-radius: 6px;">
                            <div class="layui-row">
                                <div class="layui-col-xs6">
                                    <span>APPID:</span>
                                    <span id="appid" style="margin-left: 8px;color:#239833;"></span>
                                    <a style="margin-left: 20px;color:blue;cursor: pointer;"
                                       onclick="adminAuth('appid')">修改</a>
                                </div>
                                <div class="layui-col-xs6">
                                    <span>DEVICEID:</span>
                                    <span id="deviceid"
                                          style="margin-left: 8px;color:#239833;"></span>
                                    <a style="margin-left: 20px;color:blue;cursor: pointer;"
                                       onclick="adminAuth('deviceid')">重新生成</a>
                                </div>
                                <div class="layui-col-xs6" style="margin-top:20px;">
                                    <span>设备绑定二维码:</span>
                                    <img src="/img/qr.png"
                                         style="margin-left: 8px;width:28px;height:28px;cursor:pointer;"
                                         onclick="showQr()"></img>
                                </div>
                                <div class="layui-col-xs6" style="margin-top:20px;">
                                    <span style="line-height:28px;">开启云控制:</span>
                                    <input type="checkbox"
                                           style="margin-left: 8px;color:#239833;line-height:28px;"
                                           oninput="handleInput(event)" id="cloudctrl"></input>
                                </div>
                            </div>
                            <div>
                                <div style="padding: 8px 10px;color: red;display: none;"
                                     id="restartTap2">
                                    <span>设备控制协议发生变化，重启后生效</span> <a
                                        style="margin-left: 20px;color:darkorange;cursor: pointer;"
                                        onclick="rebootSys()">立即重启</a></div>
                            </div>
                        </div>
                        <form class="layui-form" action="" lay-filter="mqtt">
                            <div class="layui-form-item">
                                <label class="layui-form-label">服务器IP</label>
                                <div class="layui-input-block">
                                    <input type="text" name="host" required lay-verify="required|ip"
                                           placeholder="请输入服务器IP" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">通讯端口</label>
                                <div class="layui-input-block">
                                    <input type="text" name="port"
                                           placeholder="请输入通讯端口,默认1883" autocomplete="off"
                                           class="layui-input"
                                           value="1883">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">用户名</label>
                                <div class="layui-input-block">
                                    <input type="text" name="username" required
                                           lay-verify="required"
                                           placeholder="请输入用户名" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">密码</label>
                                <div class="layui-input-block">
                                    <input name="password" required lay-verify="required"
                                           placeholder="请输入密码" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">启用</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="enable" lay-skin="switch">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="mqtt">立即提交
                                    </button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <form class="layui-form" action="" lay-filter="pack">
                            <div class="layui-form-item">
                                <label class="layui-form-label">升级包地址</label>
                                <div class="layui-input-block">
                                    <input type="text" name="downloadUrl" required
                                           lay-verify="required"
                                           placeholder="请输入升级包下载地址" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>


                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="pack">升级
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>

</div>

<div class="layui-footer">
    <!-- 底部固定区域 -->
</div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/sha.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/settings.js"></script>
<script type="text/javascript" src="lib/layui/layui.js"></script>
<script type="text/html" id="action">
    <a class="layui-table-link" style="cursor: pointer;"
       onclick="editDeviceProtocol({{ d.LAY_INDEX }})">编辑</a>
    <a class="layui-table-link" style="cursor: pointer;margin-left: 20px;color:red;"
       onclick="delDeviceProtocol('{{ d.action_key }}')">删除</a>
</script>
<script type="text/html" id="toolbarUser">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加用户</button>
    </div>
</script>
<script type="text/html" id="codes">
    <ul>
        {{# layui.each(d.codes, function(index, item){ }}
        <li>
            <span>{{ item.name }}</span>
            <span>[{{ item.code }}]</span>
            <span>(延时{{ item.delay || 0}}s)</span>
        </li>
        {{# }); }}
        {{# if(d.codes.length === 0){ }}
        无数据
        {{# } }}
    </ul>
</script>
<script type="text/html" id="userActionTpl">
    <a onclick="deleteUser({{d.rowid}})" class="layui-table-link" style="color: red;">删除</a>
</script>
<script>
    let roomMap = {};
    let deviceid=null;
    let customProtocols = null;
    layui.use('element', function () {
        var element = layui.element;
        element.on('tab(filter)', function (data) {
        });

        element.on('nav(filter)', function (elem) {
        });
    });
    let table = null
    layui.use(['form', 'treeSelect', 'table','layer'], function () {
        var form = layui.form;
        var layer = layui.layer;
        table = layui.table;
        loadDeviceType(form)
        form.on('submit(networkset)', function (data) {
            var field = data.field;
            saveNetworkConfig(field);
            return false;
        });

        form.on('submit(serverset)', function (data) {
            var field = data.field;
            saveServerConfig(field);
            return false;
        });

        form.on('submit(roombind)', function (data) {
            bindRoom();
            return false;
        });

        form.on('submit(serialport)', function (data) {
            saveSerialportSettings(data.field);
            return false;
        });

        form.on('submit(servertest)', function (data) {
            var field = data.field;
            testServerConfig(field);
            return false;
        });

           form.on('submit(mqtt)', function (data) {
            var field = data.field;
            saveMQTTSettings(data.field);
            return false;
        });

        form.on('submit(customSysCode)', function (data) {
            var field = data.field;
            saveCustomSysCode(data.field);
            return false;
        });

        form.on('submit(pack)', function (data) {
            var field = data.field;
            updateSystem(data.field);
            return false;
        });

        form.on('submit(pcCtrl)', function (data) {
            var field = data.field;
            saveComputerMac(field)
            return false;
        });

        form.verify({
            username: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '用户名不能有特殊字符';
                }
                if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if (/^\d+\d+\d$/.test(value)) {
                    return '用户名不能全为数字';
                }
            },
             mac: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (value.length>0&&(value.length!=12||(!(/^[A-Fa-f0-9]+$/.test(value))))) {
                    return '请输入正确的MAC地址';
                }
            }

            //我们既支持上述函数式的方式，也支持下述数组的形式
            //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
            ,
            pass: [
                /^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'
            ],
            ip: [/^(?:(?:1[0-9][0-9]\.)|(?:2[0-4][0-9]\.)|(?:25[0-5]\.)|(?:[1-9][0-9]\.)|(?:[0-9]\.)){3}(?:(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5])|(?:[1-9][0-9])|(?:[0-9]))$/, 'IP地址格式不正确']
        });
        var treeSelect = layui.treeSelect;
        var time=(new Date()).getTime();
        var nonce=Math.random().toString(36).substr(2, 15);
        var args={
            user_id:user_id,
            session:session,
            url:'/app/sys/rooms/get',
            nonce:nonce,
            time:time
        }
        var keys = Object.keys(args)
        keys = keys.sort()
        var newArgs = {}
        keys.forEach(function (key) {
            newArgs[key.toLowerCase()] = args[key]
        })

        var string = ''
        for (var k in newArgs) {
            if (newArgs[k] !== undefined) {
                string += '&' + k + '=' + newArgs[k]
            }
        }
        string = string.substr(1)
        var signature = hex_sha1(string)
        // 初始化下拉选择器
        treeSelect.render({
            elem: '#pidSelect',
            data: '/app/sys/rooms/get',
            headers:{
                user_id:user_id,
                session:session,
                sign:signature,
                nonce:nonce,
                time:time
            },
            type: 'get',
            key: {
                id: 'id',
            },
            // 节点点击回调函数
            click: function (d) {

            },
            success: function (d) {
                roomMap = {};
                if (d && Array.isArray(d)) {
                    for (var area of d) {
                        var buildings = area.children;
                        if (buildings) {
                            for (var building of buildings) {
                                var floors = building.children;
                                if (floors) {
                                    for (var floor of floors) {
                                        var rooms = floor.children;
                                        if (rooms) {
                                            for (var room of rooms) {
                                                roomMap[room.id] = area.name + "/" + building.name + "/" + room.name
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                getServerConfig(form, treeSelect)
            }
        });
        table.render({
            id: "protocolTable",
            elem: '#protocolTable' //指定原始表格元素选择器（推荐id选择器）
            , cols: [[{
                title: "指令名称",
                field: "action_name",
                align: 'center',
                width: '16%'
            },
                {
                    title: "指令标识",
                    field: "action_key",
                    align: 'center',
                    width: '20%'
                },
                {
                    title: "协议类型",
                    field: "type",
                    align: 'center',
                    width: '10%'
                },
                {
                    title: "指令集合",
                    field: "codes",
                    align: 'center',
                    templet: '#codes',
                    width: '40%'
                },
                {
                    title: "操作",
                    field: "action",
                    align: 'center',
                    templet: '#action',
                    width: '10%'
                }]]
        });

        table.render({
            elem: '#user'
            ,height: 312
            ,toolbar: '#toolbarUser'
            ,headers:{
                user_id:user_id,
                session:session
            },
            contentType:"application/json"
            ,url: '/user/admin/list'
            ,'method':"POST"
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'rowid', title: 'ID', width:80, sort: true, fixed: 'left','align':'center'}
                ,{field: 'name', title: '用户名','align':'center'}
                ,{field: 'account', title: '账号', sort: true,'align':'center'}
                ,{field: 'create_time', title: '创建时间','align':'center'}
                ,{field: 'action', title: '操作','align':'center', templet: '#userActionTpl'}
            ]]
        });
        table.on('toolbar(user)', function(obj){
            switch(obj.event){
                case 'add':
                    layer.open({
                        type: 2,
                        title:"添加用户",
                        content: './editUser.html',
                        area: ['500px', '360px']
                    });
                    break;
            };
        });
        loadNetworkSettings(form);

        httpGet('app/info/load', null,function (res) {
            if (res.code == 0) {
                var data = res.data;
                deviceid=data.deviceid
                $("#appid").text(data.appid);
                $("#deviceid").text(data.deviceid);
                 $("#cloudctrl").prop("checked", data.cloudctrl);
                 if(data.mac){
                     form.val("pcCtrl", {
                        "mac": data.mac
                    })
                 }
                 if(data.customSysCode){
                     form.val("customSysCode", {
                        "openCode": data.customSysCode.openCode,
                        "closeCode": data.customSysCode.closeCode
                    })
                 }
                var mqttConfig = data.mqtt
                if (mqttConfig) {
                    form.val("mqtt", {
                        "host": mqttConfig.host,
                        "port": mqttConfig.port,
                        "username": mqttConfig.username,
                        "password": mqttConfig.password,
                        "enable": mqttConfig.enable
                    })
                }

            }
        })
    });

    function reloadUserList(){
        table.reload('user');
    }

    function showRestartTip() {
        $("#restartTap").show()
    }


    function deleteUser(id){
        layer.confirm('确认删除该用户吗?', {
            icon: 3,
            title: '提示'
        }, function (index) {
            layer.close(index)
            sureDelUser(id)
        })
    }

    function sureDelUser(id){
        httpPost("admin/del",{id:id},function(res){
            reloadUserList()
        })
    }

    function saveComputerMac(info){
        httpPost("computer/mac",info,function(res){
            if (res.code == 0) {
               layer.msg("保存成功")
            }
        })
    }

    function saveCustomSysCode(info){
       httpPost("sys/code/custom",info,function(res){
            if (res.code == 0) {
               layer.confirm('保存成功，重启生效。现在需要重启终端吗?', {
                icon: 3,
                title: '提示'
            }, function (index) {
                //do something
                httpGet('sys/reboot',null, function (res) {
                    if (res.code == 0) {
                        var index = layer.load(2, {
                            time: 60 * 1000
                        });
                        setTimeout(function () {
                            layer.close(index);
                            window.top.location.reload();
                        }, 40000)
                    }
                });

                layer.close(index);
            });
            }
        })
    }


    function showRestartTip2(){
        $("#restartTap2").show()
    }

    function rebootSys() {
        layui.use('layer', function () {
            layer.confirm('确认现在重启终端?', {
                icon: 3,
                title: '提示'
            }, function (index) {
                //do something
                httpGet('sys/reboot',null, function (res) {
                    if (res.code == 0) {
                        var index = layer.load(2, {
                            time: 60 * 1000
                        });
                        setTimeout(function () {
                            layer.close(index);
                            window.top.location.reload();
                        }, 40000)
                    }
                });

                layer.close(index);
            });
        });
    }


    function adminAuth(action, params1, params2) {
        layui.use('layer', function () {
            var layer = layui.layer;
            layer.prompt({
                formType: 1,
                value: '',
                title: '请输入认证密码',
                area: ['300px', '20px'] //自定义文本域宽高
            }, function (value, index, elem) {
                layer.close(index);
                switch (action) {
                    case "protocol":
                        loadProtocol(value)
                        break;
                    case "addprotocol":
                        layer.open({
                            type: 2,
                            content: './editDeviceProtocol.html?pwd=' + value,
                            title: "编辑协议",
                            area: ['840px', '600px']
                        });
                        break;
                    case "deleteProtocol":
                        sureDelProtocol(value, params1)
                        break;
                    case "exportprotocol":
                        if (customProtocols == null || customProtocols.length == 0) {
                            layui.use('layer', function () {
                                var layer = layui.layer;
                                layer.msg("协议为空，不能复制", {icon: 6});
                            });
                            return;
                        }
                        layer.open({
                            type: 2,
                            content: './showDeviceProtocol.html',
                            title: "复制协议",
                            area: ['500px', '500px']
                        });
                        break;
                    case "importprotocol":
                        layer.prompt({
                            formType: 2,
                            value: '',
                            title: '请粘贴协议文本',
                            area: ['500px', '400px'],
                            maxlength: 2000
                        }, function (content, index, elem) {
                            layer.close(index);
                            importProtocol(value, content)
                        })
                        break;
                    case "deviceid":
                        updateAppInfo(value,2,null)
                        break;
                    case "appid":
                        layer.prompt({
                            formType: 0,
                            value: '',
                            title: '请输入10位字符APPID,同一单位请保证APPID相同',
                            maxlength: 10
                        }, function (appid, index, elem) {
                            if((new RegExp('[0-9A-Za-z]{10}$')).test(appid)){
                                layer.close(index);
                                updateAppInfo(value,1,appid)
                            }else{
                                layer.msg("请输入10位字符APPID", {icon: 6});
                            }


                        });
                        break;
                }
            });
        });
    }

    function loadCurrentProtocols() {
        return customProtocols;
    }

    function editDeviceProtocol(index) {
    layui.use('layer', function () {
                        var layer = layui.layer;
                         layer.open({
            type: 2,
            content: './editDeviceProtocol.html?index=' + index,
            title: "编辑协议",
            area: ['840px', '600px']
        });
                    });

    }


    function delDeviceProtocol(key) {
        layui.use('layer', function () {
            var layer = layui.layer;
            layer.confirm('确认删除该协议吗?', {icon: 3, title: '提示'}, function (index) {
                //do something
                layer.close(index);
                adminAuth("deleteProtocol", key)
            });
        });
    }

    function importProtocol(pwd, content) {
        $.ajax({
            url: "/admin/device/protocol/import",
            method: "POST",
            dataType: 'json',
            contentType: 'application/json',
            headers: {
                pwd: pwd
            },
            data: JSON.stringify({
                content: content
            }),
            success: function (res) {
                if (res.code == 0) {
                    loadProtocol(pwd)
                    showRestartTip()
                } else {
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.msg(res.msg, {icon: 6});
                    });
                }
            }
        });
    }

    function updateAppInfo(pwd,type,params){
    var obj={
    type:type,
     pwd: pwd
    }
    if(type==1){
    obj.appid=params
    }else if(type==3){
    obj.cloudctrl=params
    }
        $.ajax({
            url: "/admin/app/info/update",
            method: "POST",
            dataType: 'json',
            contentType: 'application/json',
            data: JSON.stringify(obj),
            success: function (res) {
                if (res.code == 0) {
                    var appinfo=res.data;
                    $("#appid").text(appinfo.appid)
                    $("#deviceid").text(appinfo.deviceid)
                    showRestartTip2()
                } else {
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.msg(res.msg, {icon: 6});
                    });
                }
            }
        });
    }


    function sureDelProtocol(pwd, key) {
        $.ajax({
            url: "/admin/device/protocol/del",
            method: "POST",
            dataType: 'json',
            contentType: 'application/json',
            headers: {
                pwd: pwd
            },
            data: JSON.stringify({
                key: key
            }),
            success: function (res) {
                if (res.code == 0) {
                    loadProtocol(pwd)
                    showRestartTip()
                } else {
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.msg(res.msg, {icon: 6});
                    });
                }
            }
        });
    }


    function loadProtocol(value) {
        table.reload("protocolTable", {
            method: "post",
            headers: {
                pwd: value
            },
            url: "/admin/device/protocol/load",
            done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                customProtocols = res.data
            }
        })

    }

    function loadDeviceType(form) {
        httpGet('device/type/load', null,function (res) {
            if (res.code == 0 && res.data) {
                form.val("deviceType", {
                    "deviceType": res.data.deviceType
                });
                var Version=res.data.version
                if(Version==="OLD"){
                  $(".new-version").remove()
                  $(".old-version").css("display","flex");
                }else{
                   $(".old-version").remove()
                   $(".new-version").css("display","flex");
                }
                form.render(null, 'serialport');

                loadSerialportSettings(form)

            }
        })
    }

    function showQr(){
       if(deviceid.length>0){
        layui.use('layer', function () {
                        var layer = layui.layer;
                         layer.open({
            type: 2,
            content: './qr.html?deviceid=' + deviceid,
            title: "扫码绑定设备",
            area: ['280px', '300px']
        });
                    });
       }else{
          layer.msg("请更新DEVICEID", {icon: 6});
       }

    }

    function handleInput(e){
        var checked=e.target.checked
        updateAppInfo(null,3,checked)
    }

</script>
</body>

</html>